/**
 * @file client.h
 * @brief Client class definition
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * @author VestniK (Sergey N.Vidyuk) sir.vestnik@gmail.com
 * @date 25 Jan 2009
 */
#ifndef _Client_H_
#define _Client_H_

#include <QtCore/QObject>
#include <QtCore/QUuid>
#include <QtNetwork/QAbstractSocket>

class QTcpSocket;

namespace qrs {
   class ServicesManager;
   class SessionClient;
   class GameClient;
   class PlayerClient;
}

namespace mjn {

   /**
    * @brief MJN Client class
    *
    * This class contains the MJN client logick implementation.
    */
   class Client: public QObject {
      Q_OBJECT
      public:
         explicit Client(QObject *parent = 0);
         virtual ~Client();

         /// Connect to the given host and port
         void connectToHost(const QString& host, quint16 port=0);

         void setName(const QString &name) {mName = name;}
         const QString &name() const {return mName;}

         qrs::PlayerClient *player() {return mPlayer;}
         qrs::GameClient *game() {return mGame;}
         qrs::SessionClient *session() {return mSession;}
      signals:
          void connected();
          void connectionFailed();
          void disconnected();
          void connectionError(QString msg);
      private slots:
         void onSocketConnected();
         void onSocketDisconnected();
         void onSocketError(QAbstractSocket::SocketError socket_error);
         void onSessionStarted(const QUuid &sid);
         void onNoSlots();
      private:
         Q_DISABLE_COPY(Client);
         QUuid mSid;
         QString mName;
         QTcpSocket *mSocket;
         qrs::ServicesManager *mManager;
         qrs::SessionClient *mSession;
         qrs::GameClient *mGame;
         qrs::PlayerClient *mPlayer;
   };

}

#endif
